<template>
  <div class="app-container">
    <Action ref="actionref" title="查看留言" :type="2"></Action>
    <div class="filter-container">
      <el-date-picker
        v-model="listQuery.checktime"
        type="daterange"
        range-separator="至"
        class="filter-item"
        style="width:300px"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="pickerOptions"
        value-format="yyyy-MM-dd"
      >
      </el-date-picker>
      <el-input
        v-model="listQuery.u_name"
        placeholder="请输入发帖用户名"
        clearable
        @clear="clearuname"
        class="filter-item w-200"
      />
      <el-button-group class="filter-item">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-refresh"
          @click="refresh"
        >
          重置
        </el-button>

      </el-button-group>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      height="100%"
      class="table-container"
      highlight-current-row
    >

      <el-table-column
        width="80"
        label="wid"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.wid }}
        </template>
      </el-table-column>


      <el-table-column
        width="150"
        label="发帖人"
        align="center"
      >
        <template slot-scope="scope">
          <div style="font-size:12px;color:#20a0ff;cursor: pointer" @click="onlyUser(scope.row.u_name)">{{ scope.row.u_name }}</div>
        </template>
      </el-table-column>
      <el-table-column
        width="400"
        label="标题"
        align="left"

      >
        <template slot-scope="scope" >
          <div style="color:#409EFF;font-size:14px;cursor: pointer"  @click="doAction(scope.row.wid)">
            {{ scope.row.title }}
          </div>
        </template>
      </el-table-column>

      <el-table-column
        width="135"
        label="发帖时间"
        align="center"
      >
        <template slot-scope="scope">
          <div style="font-size:12px">{{ scope.row.create_time }}</div>
        </template>
      </el-table-column>

      <el-table-column
        width="135"
        label="回复时间"
        align="center"
      >
        <template slot-scope="scope">
          <div style="font-size:12px">{{ scope.row.reply_time }}</div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="fetchData"
    />
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import Action from '@/components/wz/action'
import {getmyactionList} from '@/api/user'
import {getWzParams} from "@/api/wz";

let id = 0
export default {
  components: {
    Pagination,
    Action
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 20,
        sel: 1,
        checktime: [],
        u_name:'',
      },
      list: [],
      total: 0,
      baseData: [],
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() + 3600 * 1000 * 24 * 1);
            picker.$emit('pick', [end, start]);
          }
        }, {
          text: '本月',
          onClick(picker) {
            const now = new Date();
            const start = new Date(now.getFullYear(), now.getMonth(), 1)
            const end = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
            start.setTime(start.getTime());
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      listLoading: false,
    }
  },

  created() {
    this.WzParams()
    this.fetchData()
  },
  methods: {
    clearuname(){
      this.listQuery.u_name = ''
      this.fetchData()
    },
    search() {
      this.fetchData()
    },
    onlyUser(u_name){
      this.listQuery.u_name = u_name
      this.fetchData()
    },
    doAction(wid){
      this.$refs.actionref.openAction(wid)
    },
    WzParams() {
      let baseData = localStorage.getItem('wzbaseData')
      if (!baseData) {
        getWzParams().then(response => {
          this.baseData = response.data
          localStorage.setItem('wzbaseData', JSON.stringify(this.baseData))
        })
      } else {
        this.baseData = JSON.parse(baseData)
      }
    },
    refresh() {
      this.listQuery = {
        page: 1,
        limit: 20,
        sel: 1
      }
      this.fetchData()
    },
    fetchData(column) {
      this.listLoading = true
      if (column) {
        this.listQuery.orderFiled = column.prop
        this.listQuery.orderType = column.order
      }
      getmyactionList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    submit() {

    }
  }
}
</script>
